<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-humanResources__outbound}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.productTitle" placeholder="产品标题" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="productTitle" label="产品标题" header-align="center" align="center"></el-table-column>
        <el-table-column prop="outQuantity" label="出库数量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="outDescription" label="出库描述" header-align="center" align="center"></el-table-column>
        <el-table-column prop="outImgUrl" label="出库图片URL" header-align="center" align="center">
          <template slot-scope="scope">
            <el-image style="width: 100px; height: 100px" :src="scope.row.outImgUrl" fit="cover"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="审核状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 0" size="small" type="info">待审核</el-tag>
            <el-tag v-else-if="scope.row.status == 1" size="small" type="success">审核通过</el-tag>
            <el-tag v-else-if="scope.row.status == 2" size="small" type="danger">审核失败</el-tag>
          </template>
        </el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="outInventory(scope.row)" v-if="scope.row.status == 0">审核成功</el-button>
            <el-button type="text" size="small" @click="failInventory(scope.row)" v-if="scope.row.status == 0">审核失败</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './outbound-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/humanResources/outbound/page',
        getDataListIsPage: true,
        exportURL: '/humanResources/outbound/export',
        deleteURL: '/humanResources/outbound',
        deleteIsBatch: true
      },
      dataForm: {
        id: '',
        productTitle: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 审核通过出库
    outInventory (row) {
      this.$http.post('/humanResources/outbound/outInventory', {
        "id": row.id,
        "productId": row.productId,
        "outQuantity": row.outQuantity
      }).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.$message({
          message: this.$t('prompt.success'),
          type: 'success',
          duration: 500,
          onClose: () => {
            this.query()
          }
        })
      }).catch(() => {})
    },
    // 审核出库失败
    failInventory (row) {
      this.$http.put('/humanResources/outbound', {
        "id": row.id,
        "status": 2
      }).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.$message({
          message: this.$t('prompt.success'),
          type: 'success',
          duration: 500,
          onClose: () => {
            this.query()
          }
        })
      }).catch(() => {})
    }
  }
}
</script>
